<?php
    include '../entity/user_entity.php';
    include '../business/user_manager.php';

    $userMng       = new UserMng();
    $userEntity    = new UserEntity();

    $userEntity->id                = $_COOKIE['b2b_id'];
    $userEntity->email             = $_COOKIE['b2b_email'];
    $userEntity->passwd            = $_COOKIE['b2b_passwd'];
    $userEntity->telephone         = $_COOKIE['b2b_telephone'];
    $userEntity->details           = $_COOKIE['b2b_details'];
    $userEntity->company           = $_COOKIE['b2b_company'];
    $userEntity->firstName         = $_COOKIE['b2b_firstName'];
    $userEntity->lastName          = $_COOKIE['b2b_lastName'];
    $userEntity->address1          = $_COOKIE['b2b_address1'];
    $userEntity->address2          = $_COOKIE['b2b_address2'];
    $userEntity->city              = $_COOKIE['b2b_city'];
    $userEntity->country           = $_COOKIE['b2b_country'];
    $userEntity->province          = $_COOKIE['b2b_province'];
    $userEntity->zipCode           = $_COOKIE['b2b_zipCode'];
    $userEntity->currency          = $_POST['currency'];
    $userEntity->jobFunction       = $_POST['jobFunction'];
    $userEntity->hearUS            = $_POST['hearUS'];
    $userEntity->cadUsed           = $_POST['cadUsed'];
    $userEntity->compenents        = $_POST['compenents'];
    $userEntity->materialSpend     = $_POST['materialSpend'];
    $userEntity->supplierType      = $_POST['supplierType'];
    $userEntity->lowCost           = $_POST['lowCost'];
    $userEntity->industry          = $_POST['industry'];
    $userEntity->employees         = $_POST['employees'];
    $userEntity->userType          = $_COOKIE['b2b_userType'];
    $userEntity->inTime            = time();
    $userEntity->inUser            = "-1";

    

    if (!($id = $userMng->update($userEntity))) {
        echo "<script>alert('Email aleady exists!');</script>";
    } else {
         $_SESSION['userID'] = $id;
         $_SESSION['name'] = split('@', $userEntity->email, 0);
         $_SESSION['userType'] = $userEntity->userType;
         echo "<script>window.location.href='dashboard.php'</script>";
    }
?>
